package test4_16.demo03;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.Scanner;

public class UDPClientDoubleTest {
    public static void main(String[] args) {

        try {
            //创建客户端
            DatagramSocket ds = new DatagramSocket(1111);
            System.out.println("客户端已启用");

            //存放要发送的数据
            byte[] bytes;
            Scanner scanner = new Scanner(System.in);

            while (true){
                bytes = scanner.nextLine().getBytes();

                DatagramPacket dp = new DatagramPacket(bytes,bytes.length,InetAddress.getLocalHost(),1234);
                ds.send(dp);
                System.out.println("客户端发送成功");
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
